import {takeEvery,put} from 'redux-saga/effects'
import {REDUX_SAGA_GET_DATA_LIST} from './ActionTypes';
import axios from 'axios'
import {getInitDataList} from './ActionCreators';
import { notification } from 'antd';

const openNotification = () => {
    notification.open({
      message: 'Notification Title',
      description: 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
      onClick: () => {
        console.log('Notification Clicked!');
      },
    });
  };
function* mysaga(){
    //接收发过来的action，第二个参数是相应的操作函数
    yield takeEvery(REDUX_SAGA_GET_DATA_LIST, getListData)
}
function* getListData(){
    try{
        const res = yield axios.get('http://127.0.0.1:3002/getAllUser');
        console.log(res.data.message);
        //生成一个action
        const action = getInitDataList([1,2,3,4,5]);
        //发送一个action
        yield put(action);
        
    }catch(e){
        console.log('您的网络抽风了！！！');
        openNotification();
    }
   
}
//导出一个generation函数
export default mysaga;